#include "../subject/server.hpp"


int main()
{
    Socket connect;
    connect.CreateClient(8080, "127.0.0.1");

    int cnt = 5;
    while (cnt--)
    {
        std::string str = "hello world";
        connect.Send((void*)str.c_str(), str.size());
        std::string tmp;
        tmp.resize(str.size());
    
        int ret = connect.Read((void*)tmp.c_str(), tmp.size());
        if (ret > 0)
        {
            DBG_LOG("走到这， 说明读取成功");
            tmp[ret] = 0;
        }
        else if (ret < 0)
        {
            DBG_LOG("走到这， 说明读取失败");
        }
        else if (ret == 0)
        {
            DBG_LOG("走到这， 说明信号中断或者非阻塞读取");
        }
        DBG_LOG("%s", tmp.c_str());
        sleep(1);
    }
    cnt = 5;
    while (cnt--)
    {
        DBG_LOG("%d", cnt);
        sleep(1);
    }

    cnt = 5;
    while (cnt--)
    {
        std::string str = "hello world";
        connect.Send((void*)str.c_str(), str.size());
        std::string tmp;
        tmp.resize(str.size());
    
        int ret = connect.Read((void*)tmp.c_str(), tmp.size());
        if (ret > 0)
        {
            DBG_LOG("走到这， 说明读取成功");
            tmp[ret] = 0;
        }
        else if (ret < 0)
        {
            DBG_LOG("走到这， 说明读取失败");
        }
        else if (ret == 0)
        {
            DBG_LOG("走到这， 说明信号中断或者非阻塞读取");
        }
        DBG_LOG("%s", tmp.c_str());
        sleep(1);
    }

    return 0;
}